package com.qfedu.role.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.common.Md5;
import com.qfedu.common.R;
import com.qfedu.role.dto.RoleDto;
import com.qfedu.role.dto.StateDto;
import com.qfedu.role.pojo.Role;
import com.qfedu.role.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping
    public R<Page<Role>> searchRoles(RoleDto roleDto){
        return R.ok(roleService.getRoles(roleDto));
    }

    @PutMapping
    public R<Boolean> updateRole(@RequestBody Role role){
        return R.ok(roleService.updateById(role));
    }

    @PostMapping
    public R<Boolean> addRole(@RequestBody Role role){
        return R.ok(roleService.save(role));
    }

    @DeleteMapping("/{id}")
    public R<Boolean> deleteRole(@PathVariable("id") String id){
        Integer roleId=Integer.parseInt(id);
        return R.ok(roleService.removeById(roleId));
    }

    @PutMapping("/state")
    public R<Boolean> changeRoleState(@RequestBody StateDto stateDto){
        return R.ok(roleService.changeRoleState(stateDto));
    }



}
